Skip to content

feat(cli): enhance folder trust with configuration discovery and security warnings - #19492

Merged
galdawave merged 8 commits into
mainfrom
galzahavi/improve/foldertrust-messaging
Feb 20, 2026
Merged

feat(cli): enhance folder trust with configuration discovery and security warnings#19492
galdawave merged 8 commits into
mainfrom
galzahavi/improve/foldertrust-messaging

Conversation

@galdawave

Copy link
Copy Markdown
Contributor

Summary

This PR enhances the Folder Trust mechanism by introducing a "Discovery" phase. Before a user trusts a folder, the CLI now safely scans the .gemini directory to inform the user about what local configurations will be loaded (commands, skills, MCP servers, and settings). It also proactively flags security-sensitive settings—such as disabled sandboxes or auto-approved tools—using clear visual warnings.

Details

  • FolderTrustDiscoveryService: A safe, read-only service that identifies local configurations and security risks without executing them.
  • FolderTrustDialog Enhancement: The trust dialog now displays a detailed summary of discovered items and security warnings.
  • Improved Security UX: Warnings for sensitive settings (like `sandbox: false` or `enableAgents: true`) are highlighted in yellow to ensure user awareness before granting trust.
  • Ruthless Refactoring: The implementation was refactored to prioritize type safety (`noPropertyAccessFromIndexSignature` compliance), minimize complexity in discovery logic, and consolidate UI rendering code.
  • Example Implementation: Added an example configuration in `examples/security-warnings/` to demonstrate all possible security triggers.

Related Issues

Related to the ongoing security and folder trust enhancement initiative.

How to Validate

  1. Unit Tests:
    ```bash
    npm test -w @google/gemini-cli -- src/services/FolderTrustDiscoveryService.test.ts src/ui/components/FolderTrustDialog.test.tsx src/ui/hooks/useFolderTrust.test.ts
    ```
  2. Lint & Typecheck:
    ```bash
    npm run lint -w @google/gemini-cli
    npm run typecheck -w @google/gemini-cli
    ```
  3. Manual Verification:
    • Navigate to the provided example: `cd examples/security-warnings/`
    • Run `gemini` (ensure the folder is not already trusted).
    • Verify that the trust dialog displays "Commands", "MCP Servers", etc., and the yellow security warnings.

Pre-Merge Checklist

  • Updated relevant documentation and README (added security warnings example)
  • Added/updated tests (yes)
  • Noted breaking changes (none)
  • Validated on MacOS (npm run, npx, Seatbelt)

…rity warnings

Implement FolderTrustDiscoveryService to safely scan untrusted folders for
local configurations and security-sensitive settings. Update the trust dialog
to display these findings, providing users with transparency into what will
be loaded before they grant trust.

- Add FolderTrustDiscoveryService for read-only .gemini directory scanning
- Detect commands, skills, MCP servers, hooks, and setting overrides
- Flag security risks such as disabled sandboxes or auto-approved tools
- Update FolderTrustDialog to display discovery results and warnings
- Integrate discovery into useFolderTrust hook for real-time scanning
- Ensure dialog remains usable in small terminals with scrolling/truncation
@galdawave
galdawave requested a review from a team as a code owner February 19, 2026 00:53
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @galz10, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly upgrades the Folder Trust mechanism in the Gemini CLI. It introduces a proactive discovery process that inspects local .gemini configurations, such as commands, skills, and settings, before a folder is trusted. This allows the CLI to present users with a clear overview of what will be loaded and, crucially, to flag any security-sensitive settings with prominent warnings, thereby empowering users to make informed trust decisions and enhancing overall security awareness.

Highlights

  • Enhanced Folder Trust Mechanism: Introduced a 'Discovery' phase that safely scans the .gemini directory to identify local configurations (commands, skills, MCP servers, and settings) before a user trusts a folder.
  • Security-Sensitive Setting Warnings: Proactively flags security-sensitive settings, such as disabled sandboxes or auto-approved tools, using clear visual warnings within the trust dialog.
  • Improved User Experience: The FolderTrustDialog now displays a detailed summary of discovered items and security warnings, empowering users to make informed trust decisions.
  • Code Quality and Maintainability: Refactored the implementation to prioritize type safety (noPropertyAccessFromIndexSignature compliance), minimize discovery logic complexity, and consolidate UI rendering code.
  • New Discovery Service: Added a FolderTrustDiscoveryService for safe, read-only identification of local configurations and potential security risks without executing them.
Changelog
  • packages/cli/src/services/FolderTrustDiscoveryService.test.ts
    • Added unit tests for the FolderTrustDiscoveryService to verify its ability to discover commands, skills, MCPs, hooks, settings, and flag security warnings, as well as handle missing directories and malformed JSON.
  • packages/cli/src/services/FolderTrustDiscoveryService.ts
    • Added a new service, FolderTrustDiscoveryService, responsible for asynchronously scanning a workspace directory's .gemini folder to identify local configurations (commands, skills, MCPs, hooks, settings) and detect potential security risks, returning these as FolderDiscoveryResults.
  • packages/cli/src/ui/AppContainer.tsx
    • Updated the useFolderTrust hook integration to retrieve and pass folderDiscoveryResults to the UI state, enabling the display of discovered configurations in the trust dialog.
  • packages/cli/src/ui/components/DialogManager.tsx
    • Modified to pass the folderDiscoveryResults from the UI state to the FolderTrustDialog component.
  • packages/cli/src/ui/components/FolderTrustDialog.test.tsx
    • Expanded tests for FolderTrustDialog to cover the display of discovery results, security warnings, and error messages, including truncation logic based on terminal height and expansion behavior.
  • packages/cli/src/ui/components/FolderTrustDialog.tsx
    • Refactored the FolderTrustDialog component to integrate and display the FolderDiscoveryResults, including sections for commands, MCPs, hooks, skills, settings, security warnings, and discovery errors.
    • Implemented dynamic height adjustment and scrolling using MaxSizedBox, Scrollable, and StickyHeader components for better UI presentation.
  • packages/cli/src/ui/components/shared/MaxSizedBox.tsx
    • Enhanced MaxSizedBox by adding an onOverflowChange prop to notify when content overflows.
    • Updated the text color for overflow messages to theme.text.primary for better visibility.
  • packages/cli/src/ui/contexts/UIStateContext.tsx
    • Extended the UIState interface to include folderDiscoveryResults for storing and managing the discovered configurations and warnings within the application's UI context.
  • packages/cli/src/ui/hooks/useFolderTrust.test.ts
    • Updated to mock the FolderTrustDiscoveryService to control its behavior during tests, ensuring isolated testing of the useFolderTrust hook.
  • packages/cli/src/ui/hooks/useFolderTrust.ts
    • Modified the useFolderTrust hook to asynchronously call FolderTrustDiscoveryService.discover when a folder's trust status is undefined or false, storing the results in a new discoveryResults state variable.
    • Added a cleanup function for the async discovery operation to prevent state updates on unmounted components.
Ignored Files
  • Ignored by pattern: .gemini/** (1)
    • .gemini/settings.json
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a discovery phase for folder trust, significantly enhancing security transparency by scanning the .gemini directory and informing users about local configurations and potential risks. A critical vulnerability has been identified: the rendering of discovered items in the terminal is susceptible to terminal injection via ANSI escape sequences, which could allow an attacker to bypass security warnings and trick users into trusting malicious folders. This highlights the importance of treating all user-provided data as untrusted and applying proper sanitization. Additionally, the discovery service requires improvements in robustness, specifically regarding the validation of parsed configuration files from untrusted sources and proper management of asynchronous operations to prevent unhandled promise rejections.

Comment thread packages/cli/src/ui/components/FolderTrustDialog.tsx
Comment thread packages/cli/src/services/FolderTrustDiscoveryService.ts Outdated
Comment thread packages/cli/src/ui/hooks/useFolderTrust.ts Outdated
@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 19, 2026
@galdawave galdawave changed the title Galzahavi/improve/foldertrust messaging feat(cli): enhance folder trust with configuration discovery and security warnings Feb 19, 2026
galdawave and others added 2 commits February 19, 2026 10:18
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@github-actions

github-actions Bot commented Feb 19, 2026

Copy link
Copy Markdown

Size Change: +13 kB (+0.05%)

Total Size: 24.6 MB

Filename Size Change
./bundle/gemini.js 24.6 MB +13 kB (+0.05%)
ℹ️ View Unchanged
Filename Size
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB
./bundle/sandbox-macos-strict-open.sb 4.82 kB
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB

compressed-size-action

- Robust JSON Parsing: Update `FolderTrustDiscoveryService` to handle non-object, null, or array values in `settings.json` without crashing, and add regression tests for these cases.
- Type Safety: Fix unsafe type assertions in `FolderTrustDiscoveryService` using type guards (`isRecord`) and `instanceof Error` for better runtime safety and ESLint compliance.
- ANSI Stripping: Use `strip-ansi` in `FolderTrustDialog` to ensure that raw ANSI escape codes from discovery errors, security warnings, or settings are not rendered as text in the UI.
- UI Refinements:
  - Update `MaxSizedBox` to use `theme.text.secondary` for truncation messages.
  - Fix `Scrollable` auto-scroll logic to correctly identify "at bottom" state and default to top-aligned scrolling for new content unless `scrollToBottom` is explicitly set.
- Test Improvements: Update `FolderTrustDialog` tests to properly wait for rendering (`waitUntilReady`) and add coverage for ANSI stripping.
@galdawave
galdawave requested review from a team as code owners February 19, 2026 22:56

@g-samroberts g-samroberts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for docs.

@galdawave
galdawave enabled auto-merge February 20, 2026 00:48
@galdawave
galdawave added this pull request to the merge queue Feb 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Feb 20, 2026
@galdawave
galdawave added this pull request to the merge queue Feb 20, 2026
Merged via the queue into main with commit d24f10b Feb 20, 2026
27 checks passed
@galdawave
galdawave deleted the galzahavi/improve/foldertrust-messaging branch February 20, 2026 18:37
@galdawave galdawave linked an issue Feb 20, 2026 that may be closed by this pull request
spencer426 pushed a commit that referenced this pull request Feb 20, 2026
…rity warnings (#19492)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
sripasg pushed a commit that referenced this pull request Feb 27, 2026
…rity warnings (#19492)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
tripleyoung pushed a commit to tripleyoung/gemini-cli that referenced this pull request Feb 27, 2026
…rity warnings (google-gemini#19492)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
tripleyoung pushed a commit to tripleyoung/gemini-cli that referenced this pull request Feb 27, 2026
…rity warnings (google-gemini#19492)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
…rity warnings (google-gemini#19492)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
cocosheng-g pushed a commit that referenced this pull request May 6, 2026
…rity warnings (#19492)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@sripasg sripasg added the size/xl An extra large PR label Jun 2, 2026
software-0ficial pushed a commit to software-0ficial/gemini-cli that referenced this pull request Jul 9, 2026
…rity warnings (google-gemini#19492)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/xl An extra large PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Folder trust dialog is unclear

4 participants